import quantities
import sys

import os
if sys.platform == 'win32':
    sys.path.append('..\\..\\src\\')
    sys.path.append('..\\..\\..\\..\\famouso\\Bindings\\Python\\')
else:
    sys.path.append('../../src/')
    sys.path.append('../../../../famouso/Bindings/Python/')

from pyFAMOUSO.publisher import PublisherEventChannel
from pyFAMOUSO.event import Event

from abstract_node.definition import AbstractNode
from abstract_node.abstract_output import AbstractNetworkOutput

if __name__ == "__main__":    
    print "-----------------------------------------------------"    
    print "Test of the Syntax check of the Abstract Node class"
    print "-----------------------------------------------------"
   
    print "\n--> Read data sheet ..."
    data_sheet='../datasheets/events/'+"Posi_CA_.xml"
    MyNode=AbstractNode(eventDataSheet=data_sheet,
                               appName="Smart IR Sensor")
    print MyNode
    
    print "----------------------------------------------------"
    print "\n\n--> Test of different measurement and attribute format faults ... \n"

    print "--> Add Measurement value - wrong key"
    MyNode.event.set_value(2, 'Measurent')   
    print "\n--> Add Measurement value - wrong size without quantities"
    MyNode.event.set_value(2, 'Measurement')
    print "\n--> Add Measurement value - correct size without quantities"    
    MyNode.event.set_value([2, 12], 'Measurement')
    print "\n--> Add Measurement value - correct size with wrong quantities"    
    MyNode.event.set_value([2, 12]*quantities.second, 'Measurement')
    print "\n--> Add Measurement value - wrong data types"    
    MyNode.event.set_value([2000, 1200]*quantities.centimeter, 'Measurement')
    print "\n--> Add Measurement value - correct"    
    MyNode.event.set_value([2, 12]*quantities.centimeter, 'Measurement')
     
    print "\n--> MyNode ready to publish ?", MyNode.event.complete()
    print MyNode.event   
    print "\n--> Publish event"
    MyNode.trigger()
    print "\n\n"  
    
    print "\n--> Add Measurement value - correct"    
    MyNode.event.set_value([2, 12]*quantities.centimeter, 'Measurement') 
    print "--> Add Timestamp value"
    MyNode.event.set_value(5.0*quantities.second, 'Timestamp')
    print "--> Add Uncertainty value"
    MyNode.event.set_value([0.5]*quantities.centimeter**2, 'Uncertainty')
    print "--> Add Validity value"
    MyNode.event.set_value([2], 'Validity')
    print "--> Add Position value"
    MyNode.event.set_value([100, 200, 0]*quantities.centimeter, 'Position')
    print "--> Add Orientation value"
    MyNode.event.set_value([100, 200, 0]*quantities.degree, 'Orientation')      
    print "\nMyNode ready to publish ?", MyNode.event.complete()
        
    print "\nPublish event"
    MyNode.trigger()
    
    
    print "\nAfter Reset only static parts are available for new publication"
    print MyNode.event   
    print "\nAus Maus"